package com.amigo.online.provider.video.util;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import com.amigo.online.common.param.result.AdvBundleInfo;
import com.amigo.online.common.param.result.MusicInfo;
import com.amigo.online.common.param.result.VideoInfo;
import com.amigo.online.common.param.result.VideoInfo.VideoUserInfo;
import com.amigo.online.provider.video.model.entity.AdvBundle;
import com.amigo.online.provider.video.model.entity.Music;
import com.amigo.online.provider.video.model.entity.Video;

public class ConvertUtil {
    public static VideoInfo videoToVideoInfo(Video video) {
        if (video == null) {
            return null;
        }

        VideoInfo info = new VideoInfo();
        info.setId(video.getId());
        info.setUserId(video.getUserId());
        info.setVideo(video.getVideo());
        info.setCover(video.getCover());
        info.setDuration(video.getDuration());
        info.setHref(video.getHref());
        info.setAds(video.getAds());
        info.setTitle(video.getTitle());
        info.setContent(video.getContent());
        info.setType(video.getType());
        info.setRecommended(video.getRecommended());
        info.setLongitude(video.getLongitude());
        info.setLatitude(video.getLatitude());
        info.setUp(video.getUp());
        info.setLook(video.getLook());
        info.setComment(video.getComment());
        info.setDestroy(video.getDestroy());
        info.setCreatedTime(video.getCreatedTime());
        info.setMusic(musicToMusicInfo(video.getMusic()));
        info.setWaterMarkVideo(video.getWaterMarkVideo());
        VideoUserInfo user = new VideoUserInfo();
        user.setAvatar(video.getAvatar());
        user.setNickname(video.getNickname());
        info.setUser(user);
        info.setHeight(video.getHeight());
        info.setWidth(video.getWidth());
        info.setLocationId(video.getLocation_id() == null ? null : Long.valueOf(video.getLocation_id()));
        info.setShare(video.getShare());
        info.setMusicId(video.getMusicId());
        info.setAllowe_promoted(video.getAllowe_promoted());
        return info;
    }

    public static MusicInfo musicToMusicInfo(Music music) {
        if (music == null) {
            return null;
        }

        MusicInfo musicInfo = new MusicInfo();
        musicInfo.setId(music.getId());
        musicInfo.setUserId(music.getUserId());
        musicInfo.setName(music.getName());
        musicInfo.setMusic(music.getMusic());
        musicInfo.setCategory(music.getCategory());
        musicInfo.setCover(music.getCover());
        musicInfo.setRecommended(music.getRecommended());
        musicInfo.setVideoId(music.getVideoId());
        musicInfo.setUsed(music.getUsed());
        musicInfo.setType(music.getType());
        musicInfo.setCreatedTime(music.getCreatedTime());
        musicInfo.setAuthor(music.getAuthor());
        musicInfo.setDuration(music.getDuration());
        return musicInfo;
    }

    public static List<VideoInfo> videosToVideoInfos(List<Video> videoList) {
        if (videoList == null) {
            return null;
        }

        List<VideoInfo> videoInfoList = new ArrayList<VideoInfo>();
        videoInfoList = videoList.stream().map(e ->
                new VideoInfo(e.getId(), e.getUserId(), e.getVideo(), e.getCover(), e.getDuration(),
                        e.getHref(), e.getAds(), e.getType(), e.getUp(), e.getLook(), e.getComment(),
                        e.getLongitude(), e.getLatitude(), e.getTitle(), e.getContent(), e.getCreatedTime(),
                        e.getDestroy(), e.getRecommended(), musicToMusicInfo(e.getMusic()), e.getNickname(), e.getAvatar(),
                        e.getWidth(), e.getHeight(), e.getShare(), e.getAreaId(), e.getMusicId(), e.getWaterMarkVideo(), e.getAllowe_promoted())
        ).collect(Collectors.toList());

        return videoInfoList;
    }

    public static List<MusicInfo> musicsToMusicsInfo(List<Music> musicList) {
        if (musicList == null) {
            return null;
        }
        List<MusicInfo> musicInfoList = new ArrayList<MusicInfo>();
        musicInfoList = musicList.stream().map(e ->
                new MusicInfo(e.getId(), e.getUserId(), e.getName(), e.getMusic(), e.getCategory(),
                        e.getCover(), e.getRecommended(), e.getVideoId(), e.getUsed(),
                        e.getType(), e.getCreatedTime(), e.getAuthor(), e.getCollected(), e.getDuration())
        ).collect(Collectors.toList());

        return musicInfoList;
    }


    public static List<AdvBundleInfo> advBundleToAdvBundleInfo(List<AdvBundle> advBundleList) {
        if (advBundleList == null) {
            return null;
        }
        List<AdvBundleInfo> advBundleInfoList = new ArrayList<AdvBundleInfo>();
        advBundleInfoList = advBundleList.stream().map(e ->
                new AdvBundleInfo(e.getCode(), e.getName(), e.getCount())
        ).collect(Collectors.toList());

        return advBundleInfoList;
    }

}
